<template>
  <template v-if="func.isEmpty(tagData.type)">
    <el-icon v-if="tagData.icon" class="tag-icon">
      <svg-icon :icon-class="tagData.icon" />
    </el-icon>
    <span class="tag-label">{{ tagData.label }}</span>
  </template>
  <template v-else>
    <div :class="[
      'custom-tag',
      `custom-tag--${tagData.type || 'default'}`,
      `custom-tag--${tagData.effect || 'plain'}`,
      tagData.cls
    ]">
      <el-icon v-if="tagData.icon" class="tag-icon">
        <svg-icon :icon-class="tagData.icon" />
      </el-icon>
      <span class="tag-label">{{ tagData.label }}</span>
    </div>
  </template>
</template>

<script setup lang="ts">
import { func } from '@/utils/func';
import { computed } from 'vue'
interface Props {
  // 字典数据数组
  type?: 'default' | 'success' | 'warning' | 'danger' | 'info' | 'primary',
  effect?: 'plain' | 'light' | 'dark',
  cls?: string,
  icon?: string,
  label?: string
}

const props = withDefaults(defineProps<Props>(), {})

const tagData = computed(() => {
  return {
    type: props.type || '',
    effect: props.effect || 'plain',
    cls: props.cls || '',
    icon: props.icon || '',
    label: props.label || ''
  }
});
</script>


<style scoped>
/* 基础标签样式 */
.custom-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  transition: all 0.2s ease-in-out;
  cursor: default;
  white-space: nowrap;
  vertical-align: middle;
}

/* Default 类型样式 */
.custom-tag--default.custom-tag--plain {
  background-color: #f5f7fa;
  color: #606266;
  border-color: #dcdfe6;
}

.custom-tag--default.custom-tag--light {
  background-color: #f0f2f5;
  color: #606266;
  border-color: transparent;
}

.custom-tag--default.custom-tag--dark {
  background-color: #b3b6bb;
  color: #ffffff;
  border-color: #b3b6bb;
}

/* Success 类型样式 */
.custom-tag--success.custom-tag--plain {
  background-color: #f0f9ff;
  color: #67c23a;
  border-color: #b3e19d;
}

.custom-tag--success.custom-tag--light {
  background-color: #e8f5e8;
  color: #529b2e;
  border-color: transparent;
}

.custom-tag--success.custom-tag--dark {
  background-color: #85ce61;
  color: #ffffff;
  border-color: #85ce61;
}

/* Warning 类型样式 */
.custom-tag--warning.custom-tag--plain {
  background-color: #fdf6ec;
  color: #e6a23c;
  border-color: #f5dab1;
}

.custom-tag--warning.custom-tag--light {
  background-color: #faecd8;
  color: #b88230;
  border-color: transparent;
}

.custom-tag--warning.custom-tag--dark {
  background-color: #ebb563;
  color: #ffffff;
  border-color: #ebb563;
}

/* Danger 类型样式 */
.custom-tag--danger.custom-tag--plain {
  background-color: #fef0f0;
  color: #f56c6c;
  border-color: #fbc4c4;
}

.custom-tag--danger.custom-tag--light {
  background-color: #fde2e2;
  color: #c45656;
  border-color: transparent;
}

.custom-tag--danger.custom-tag--dark {
  background-color: #f78989;
  color: #ffffff;
  border-color: #f78989;
}

/* Info 类型样式 */
.custom-tag--info.custom-tag--plain {
  background-color: #f4f4f5;
  color: #909399;
  border-color: #d3d4d6;
}

.custom-tag--info.custom-tag--light {
  background-color: #f0f0f0;
  color: #73767a;
  border-color: transparent;
}

.custom-tag--info.custom-tag--dark {
  background-color: #a6a9ad;
  color: #ffffff;
  border-color: #a6a9ad;
}

/* Primary 类型样式 */
.custom-tag--primary.custom-tag--plain {
  background-color: #ecf5ff;
  color: #409eff;
  border-color: #b3d8ff;
}

.custom-tag--primary.custom-tag--light {
  background-color: #e6f7ff;
  color: #337ecc;
  border-color: transparent;
}

.custom-tag--primary.custom-tag--dark {
  background-color: #66b1ff;
  color: #ffffff;
  border-color: #66b1ff;
}

/* 图标样式 */
.tag-icon {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  flex-shrink: 0;
}

/* 文字样式 */
.tag-label {
  vertical-align: middle;
  line-height: 1;
  flex-shrink: 0;
}

/* 悬停效果 */
.custom-tag:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .custom-tag {
    font-size: 11px;
    padding: 3px 8px;
  }
}
</style>